package com.lhl.servlet;

import com.lhl.dao.StudentDao;
import com.lhl.dao.StudentDaoImpl;
import com.lhl.entity.Student;
import com.lhl.util.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/deleteStu")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        StudentDao dao = new StudentDaoImpl();
        int i = dao.deleteStudent(id);

        List<Student> students = dao.queryAllStudents();
        response.getWriter().print(JsonUtils.getJson(dao.queryAllStudents()));
    }
}
